package logic

import (
	"context"
	"house/models"

	"house/house_rpc/house_rpc"
	"house/house_rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLogic {
	return &GetLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetLogic) Get(in *house_rpc.GetRequest) (*house_rpc.GetResponse, error) {
	// todo: add your logic here and delete this line
	var HouseData models.HouseData
	var Data house_rpc.GetResponse
	var Data_house house_rpc.House
	if err := models.DB.Model(&models.House{}).Joins("join users on houses.user_id = users.id").Select("*").Where("houses.id = ?", in.Id).Scan(&HouseData).Error; err != nil {
		return &house_rpc.GetResponse{}, err
	}
	Data_house.HouseName = HouseData.HouseName
	Data_house.Address = HouseData.HouseName
	Data_house.Status = HouseData.Status
	Data_house.Price = float32(HouseData.Price)
	Data.House = &Data_house
	Data.UserName = HouseData.UserName
	return &Data, nil
}
